class Solution:
    def compress(self, chars):
        """
        :type chars: List[str]
        :rtype: int
        """
        l = len(chars)
        count = 1
        i = 1

        while i <= l:
            c = chars.pop(0)
            if i == l or chars[0] != c :
                chars.append(c)
                if count > 1:
                    chars.extend(list(str(count)))
                count = 1
            else:
                count += 1

            i += 1

        return len(chars)

s = Solution()
print(s.compress(["a","a","b","b","c","c","c"]))
print(s.compress(["a"]))
print(s.compress(["a","b","b","b","b","b","b","b","b","b","b","b","b"]))

